package com.gti.mobilsafe;

import com.gti.mobilsafe.receiver.AdminReceiver;

import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Setup4Activity extends SetupBaseActivity {

	private TextView selectContactTextView;
	private EditText setup3SelectcontactEV;
	private SharedPreferences sharePreferences;
	private String safeNumber;
	private Button finishGuardButton;
	private CheckBox checkBox;
	
	@Override
	public void setView() {
		setContentView(R.layout.setup4);
		finishGuardButton = (Button) findViewById(R.id.setup4_finshgurard_bt);
		finishGuardButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				sharePreferences = getSharedPreferences("config", MODE_PRIVATE);
				Editor editor = sharePreferences.edit();
				editor.putBoolean("issetup", true);
				editor.commit();
				Intent intent = new Intent(Setup4Activity.this,LostProtectedActivity.class);
				startActivity(intent);
				
			}
		});
		checkBox  = (CheckBox) findViewById(R.id.setup4_startfuc_cb);
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked == true){
					activeDeviceAdmin();
				}
				
			}
		});
      
	}

	@Override
	public void findView() {
		

	}

	@Override
	public void showPre() {
		loadActivity(Setup3Activity.class);
		finish();

	}

	@Override
	public void showNext() {
	
		

	}
	
	public void activeDeviceAdmin(){
		Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		ComponentName mDeviceAdminSimple = new ComponentName(this, AdminReceiver.class);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSimple);
		intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "why add the deivce admin");
		startActivity(intent);
	}
	


}
